﻿Imports System.Drawing

Namespace KnobControl
    ''' <summary>
    ''' Summary description for Utility.
    ''' </summary>
    Public Class Utility
        Public Shared Function getDarkColor(ByVal c As Color, ByVal d As Integer) As Color
            Dim r As Byte = 0
            Dim g As Byte = 0
            Dim b As Byte = 0

            If c.R > d Then
                r = CByte(c.R - d)
            End If
            If c.G > d Then
                g = CByte(c.G - d)
            End If
            If c.B > d Then
                b = CByte(c.B - d)
            End If

            Dim c1 As Color = Color.FromArgb(r, g, b)
            Return c1
        End Function
        Public Shared Function getLightColor(ByVal c As Color, ByVal d As Integer) As Color
            Dim r As Byte = 255
            Dim g As Byte = 255
            Dim b As Byte = 255

            If c.R + d < 255 Then
                r = CByte(c.R + d)
            End If
            If c.G + d < 255 Then
                g = CByte(c.G + d)
            End If
            If c.B + d < 255 Then
                b = CByte(c.B + d)
            End If

            Dim c2 As Color = Color.FromArgb(r, g, b)
            Return c2
        End Function

        ''' <summary>
        ''' Method which checks is particular point is in rectangle
        ''' </summary>
        ''' <param name="p">Point to be Chaecked</param>
        ''' <param name="r">Rectangle</param>
        ''' <returns>true is Point is in rectangle, else false</returns>
        Public Shared Function isPointinRectangle(ByVal p As Point, ByVal r As Rectangle) As Boolean
            Dim flag As Boolean = False
            If p.X > r.X AndAlso p.X < r.X + r.Width AndAlso p.Y > r.Y AndAlso p.Y < r.Y + r.Height Then
                flag = True
            End If
            Return flag

        End Function
        Public Shared Sub DrawInsetCircle(ByRef g As Graphics, ByVal r As Rectangle, ByVal p As Pen)
            Dim p1 As New Pen(getDarkColor(p.Color, 50))
            Dim p2 As New Pen(getLightColor(p.Color, 50))
            For i As Integer = 0 To p.Width - 1
                Dim r1 As New Rectangle(r.X + i, r.Y + i, r.Width - i * 2, r.Height - i * 2)
                g.DrawArc(p2, r1, -45, 180)
                g.DrawArc(p1, r1, 135, 180)
            Next
        End Sub
    End Class
End Namespace
